package com.tools;

import java.io.*;
import java.util.ArrayList;

/**
 * @author 陈Ser
 * @ClassName Tool
 * @description: TODO
 * @Date 2021/9/10 14:24
 * @Version 1.0
 */
public class Tool<E> {

    private void savaObject(Object obj, String strPath) {
        try {
            FileOutputStream fileOut =
                    new FileOutputStream(strPath);
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(obj);
            out.close();
            fileOut.close();
        } catch (IOException i) {
            i.printStackTrace();
        }
    }

    private Object loadObject(String strPath) throws IOException {
        Object obj = null;
        try {
            FileInputStream fileIn = new FileInputStream(strPath);
            ObjectInputStream in = new ObjectInputStream(fileIn);
            obj = in.readObject();
            in.close();
            fileIn.close();
        } catch (ClassNotFoundException c) {
            System.out.println("class not found");
            c.printStackTrace();
            return obj;
        }
        return obj;
    }


    /**
     * 去除重复，使用的ArrayList.indexof()-->o.equals()
     *
     * @param arrayList 去除重复的数组
     * @return 返回新的数组
     * @author 陈Ser
     * @date 16:50 2021/9/9
     * @deprecated 去除重复，使用的ArrayList.indexof()调用item的equals()
     */
    public ArrayList<E> removalRepeatability(ArrayList<E> arrayList) {
        ArrayList<E> reArrayList = new ArrayList<>();
        for (E item : arrayList) {
            if (reArrayList.indexOf(item) == -1) {
                reArrayList.add(item);
            }
            ;
        }
        return reArrayList;
    }
}
